<?php
namespace app\index\controller;

use think\Controller;
use think\Db;
class MeritPayDistribute extends Controller{
	
    public function index()
    {
        return $this->fetch();
    }

    public function getMeritPayDistribute(){
        $page = request()->param('page');
        $limit = request()->param('limit');



        //初始化切块数据分配
        //超教学工作量、超管理工作量、专项业绩奖励
        $meritPayDistributeLsit =  array();
        //汇总数据绩效工资切块数据数据
        $companyList = Db('company')->select();

        foreach ($companyList as $company){
            $meritPayDistribute = [
                'over_teaching_workload' => Db('merit_pay_cut')
                    ->join('base_info','merit_pay_cut.user_id = base_info.user_id')
                    ->where('base_info.company_id',$company['id'])
                    ->sum('teaching_task_fee'),
                'over_management_workload' => Db('merit_pay_cut')
                    ->join('base_info','merit_pay_cut.user_id = base_info.user_id')
                    ->where('base_info.company_id',$company['id'])->sum('manage_fee'),
                'special_performance_award' => Db('merit_pay_cut')
                    ->join('base_info','merit_pay_cut.user_id = base_info.user_id')
                    ->where('base_info.company_id',$company['id'])
                    ->sum('vacancy_subsidy+special_subsidy+annual_assess_fee+principal_award_fund+deduction_major_liability+mediation_funds'),
                'company' => $company['company'],
                'id' => $company['id']
            ];
            array_push($meritPayDistributeLsit,$meritPayDistribute);

        }
        $count = Db('company')->count();



        $msg = [
            'code' => 0,
            'msg' => '查询成功',
            'data' => $meritPayDistributeLsit,
            'count' => $count
        ];

        echo json_encode($msg);
    }


	
}